package com.tianxiao.faas.application.web.corner;

import com.tianxiao.faas.api.param.corner.SearchShopPageParam;
import com.tianxiao.faas.api.param.corner.SearchShopResult;
import com.tianxiao.faas.api.param.corner.ShopDetailsResult;
import com.tianxiao.faas.application.aop.AuthenticationContextHolder;
import com.tianxiao.faas.biz.service.corner.ShopService;
import com.tianxiao.faas.common.access.Access;
import com.tianxiao.faas.common.constants.CommonConstants;
import com.tianxiao.faas.common.result.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("app/search")
public class SearchController {

    @Resource
    private ShopService shopService;

    @RequestMapping(value = "/shop")
    @Access
    public Result<List<SearchShopResult>> searchShop(@RequestBody SearchShopPageParam param) {
        Long userId = AuthenticationContextHolder.currentContext().getUserId();
        List<SearchShopResult> shopResults = shopService.search(param, CommonConstants.SHOP_TOP, CommonConstants.SHOP_KIND, userId);
        return Result.builder().success(true).data(shopResults);
    }

    @RequestMapping(value = "/scene")
    @Access
    public Result<List<SearchShopResult>> searchScene(@RequestBody SearchShopPageParam param) {
        Long userId = AuthenticationContextHolder.currentContext().getUserId();
        List<SearchShopResult> scene = shopService.search(param, CommonConstants.SCENE_TOP, CommonConstants.SCENE_KIND, userId);
        return Result.builder().success(true).data(scene);
    }

    @RequestMapping(value = "/shop/details")
    @Access
    public Result<ShopDetailsResult> shopDetails(Long shopId) {
        Long userId = AuthenticationContextHolder.currentContext().getUserId();
        ShopDetailsResult shopResults = shopService.shopDetails(shopId, userId);
        return Result.builder().success(true).data(shopResults);
    }

}
